const koa = require("koa");
const static=require('koa-static');
const koaHbs= require("koa-handlebars");
const app =new koa();

app.use(static('./public'));

app.use(koaHbs({
    cache:app.env!=='development',
    defaultLayout: "main",
    layoutsDir:'views/layouts',
    partialsDir:'views/partials',
    helpers:{
        section(name, opts){
            if(!this._sections)this._sections={};
            this._sections[name]=opts.fn(this);
            return null;
        },
        addOne(name,opts){
            return +name+1;
        }
    }
}));

let router=require('./routes/index');

app.use(router.routes()).use(router.allowedMethods());

app.listen(4000,()=>{
   console.log(`[koa-views]:4000---${new Date().toLocaleTimeString()}`);
});